#ifndef __COMM_HPP
#define __COMM__HPP

#include<sys/ipc.h>
#include<sys/types.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include"log.hpp"
using namespace std;

#define size 4096
Log log;
const string pathname="/home";
const int proj_id=0x888;


key_t getkey()
{
    key_t k=ftok(pathname.c_str(),proj_id);
    if(k<0) 
    {
        exit(1);
    }
    return k;
}
int GetShareMemHelper(int flag)
{
    key_t k=getkey();
    int shmid=shmget(k,size,flag);
    if(shmid<0)
    {
        log(Fatal,"create share memory error: %s",strerror(errno));
        exit(2);
    }
    log(Info,"create share memory success,shimd:%d",shimd);
    return shmid;
}  

int CreateShm()
{
    return GetShareMemHelper(IPC_CREAT| IPC_EXCL| 0666);
}
int GetShm()
{
    return GetShareMemHelper(IPC_CREAT);
}

#endif